package com.abc.robot01.activity

import android.os.Bundle
import android.util.Log
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.Modifier
import com.abc.robot01.databinding.FragmentH52Binding

/**
 * 报价H5页面
 *   adb shell am start -n com.abc.robot01/.activity.BaoJia2Activity --es url "https://pcs-h5-dev.xmlights.com/robot/imbedding/peicelist"
 */
class BaoJia2Activity : BaseVoiceActivity() {
    private lateinit var binding: FragmentH52Binding
    private lateinit var webView: WebView
//    private val viewModel: ShangPinKuViewModel by viewModels()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
      val  url2 = intent.getStringExtra("url");
        Log.e(TAG, "url: "+url2);
        binding = FragmentH52Binding.inflate(layoutInflater);
        setContentView(binding.root)

        binding.composeView.setContent {
            MaterialTheme {
                Box {
//                    Image(painter = painterResource(id = R.drawable.z1), contentDescription = "")
                    Row(modifier = Modifier.padding(30.px)) {
                        BackButton {
                        }
                    }

//                    OutlinedButton(
//                        onClick = {
//                            startActivity<HuXingXuanZheActivity>() {
//                                putExtra("designPackageId", 111)
//                            }
//                        },
//                        border = BorderStroke(width = 1.dp, color = Color.White.copy(alpha = 0.5f)),
//                        contentPadding = PaddingValues(0.dp),
//                        modifier = Modifier
//                            .padding(0.dp)
//                            .offset(x = 482.dp, y = 224.dp)
//                            .size((52 * 3.5f).toInt().px, (28 * 3.5f).toInt().px),
//                    ) {
//                        Text(
//                            text = "查看报价",
//                            style = TextStyle(color = Color.White), fontSize = 30.mysp
//                        )
//                    }
                }
            }
//            Row(
//                modifier = Modifier.padding(
//                    start = 30.px,
//                    end = 30.px,
//                    top = 30.px
//                )
//            ) {
//                BackButton {
//                }
//            }
        }

        webView=binding.webView;

        // 清除缓存
        webView.clearCache(true)
        webView.settings.javaScriptEnabled = true
        webView.settings.cacheMode = WebSettings.LOAD_NO_CACHE
        webView.settings.domStorageEnabled = true
        webView.webViewClient = WebViewClient()

//            // 设置 WebViewClient 以便在 WebView 中加载页面
////            loadUrl("https://www.example.com")  // 替换为你想加载的 URL
//        }
//
//        binding.root.addView(webView)
//        webView.loadUrl("https://baidu.com")
        webView.loadUrl(url2!!)
//        url?.let{
//            webView.loadUrl(url)
//            Log.e(TAG, "url: 加载成功： "+url);
//        }
        }

    companion object {
        const val TAG = "报价H5页面"
    }
}

